#include "io.h"
#include <string.h>
#include <assert.h>
#include <malloc.h>

sFile* statFile(const char* name)
{
  sFile* lpFile=(sFile*)calloc(1,sizeof(sFile));
  lpFile->info=(struct stat*)calloc(1,sizeof(struct stat));
  if(stat(name,lpFile->info)!=0)
  {
    free(lpFile);
    return NULL;
  }
  else
  {
    lpFile->name=(char*)calloc(strlen(name),sizeof(char));
    strcpy(lpFile->name,name);
    return lpFile;
  }
}

bool readFile(sFile* lpFile)
{
  file_buffer_t* lpBuf;
  assert(lpFile!=NULL);
  if((lpFile->fd=fopen(lpFile->name,"r"))<0)
  {
    return false;
  }
  else
  {
    lpFile->buffer=newBuffer();
    lpBuf=lpFile->buffer;
    int tmp;
    while((tmp=fgetc(lpFile->fd))!=EOF)
    {
      addBufferChar(lpBuf,tmp);
    }
    fclose(lpFile->fd);
  }
  lpBuf->cursorCol=0;
  lpBuf->cursorRow=0;
  return true;

}


bool    writeFile(sFile*){
    printf("No Write File Functionality At This Time\n");
    return true;
}



